package common;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Display extends JFrame {

	private static final long serialVersionUID = 7447474756312301596L;
	private static JTextArea display = null;

	public Display() {
		display = new JTextArea();
		display.setEditable(false);
		display.setWrapStyleWord(true);

		JScrollPane jScrollPane = new JScrollPane();
		jScrollPane.setViewportView(display);

		JPanel jContentPane = new JPanel();
		jContentPane.setLayout(new BorderLayout());
		jContentPane.add(jScrollPane, BorderLayout.CENTER);

		this.setSize(new Dimension(1000, 500));
		this.setContentPane(jContentPane);
		this.setTitle("Generador de paquetes");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.centrarPantalla();
	}

	private void centrarPantalla() {
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation((dim.width - getSize().width) / 2, (dim.height - getSize().height) / 2);
	}

	public static void log(String line) {
		if (display != null) {
			Date d = new Date();
			display.append(d.toString() + ": " + line + "\n");
			display.setCaretPosition(display.getDocument().getLength());
		}
	}

	public static void rawLog(String line) {
		if (display != null) {
			display.append(line);
			display.setCaretPosition(display.getDocument().getLength());
		}
	}
}
